//
//  AddCheckingRecordView.m
//  YIJU2.0HD
//
//  Created by 张金国 on 16/5/20.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "AddCheckingRecordView.h"
#import "Masonry.h"

#define kLayerCornerRadius 5.0f
#define kLayerBorderWidth 0.5f

#define kTextFieldBorderColor [UIColor colorWithRed:0.7686 green:0.7725 blue:0.7725 alpha:1.0].CGColor
#define kTextView1BorderColor [UIColor colorWithRed:0.7608 green:0.8745 blue:0.9216 alpha:1.0].CGColor//看房记录
#define kTextView2BorderColor [UIColor colorWithRed:0.9804 green:0.9569 blue:0.8118 alpha:1.0].CGColor//提出问题
#define kTextView3BorderColor [UIColor colorWithRed:0.8941 green:0.7569 blue:0.749 alpha:1.0].CGColor//访问印象
#define kButtonBackgroundColor [UIColor colorWithRed:0.898 green:0.902 blue:0.9137 alpha:1.0]//按钮背景色
#define kButtonBorderColor [UIColor colorWithRed:0.851 green:0.8627 blue:0.8784 alpha:1.0].CGColor//按钮边框色
#define kCancelBtnTitleColor [UIColor colorWithRed:0.8471 green:0.4784 blue:0.4235 alpha:1.0]//取消按钮title色
#define kSureBtnTitleColor [UIColor colorWithRed:0.3725 green:0.7176 blue:0.8627 alpha:1.0]//保存按钮title色

@interface AddCheckingRecordView ()

@property (nonatomic ,strong)UILabel   *navLabel;

@property (nonatomic ,strong)UIButton  *cancleButton;

@property (nonatomic ,strong)UIButton  *sureButton;

@end

@implementation AddCheckingRecordView
#pragma mark - init
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:0.9961 green:1.0 blue:1.0 alpha:1.0];
        [self setupConstraints];
    }
    return self;
}

#pragma mark - private
- (void)setupConstraints {
    
    [self.navLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.equalTo(@70);
    }];
    
    [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.navLabel.centerY);
        make.right.equalTo(self.navLabel.mas_right).offset(-TenOffsetViewMargin);
        make.height.equalTo(@30);
        make.width.equalTo(@60);
    }];
    
    [self.cancleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.navLabel.centerY);
        make.right.equalTo(self.sureButton.mas_left).offset(-TenOffsetViewMargin);
        make.height.equalTo(self.sureButton);
        make.width.equalTo(self.sureButton);
    }];
    UIView  *tempView = [[UIView alloc]init];
    tempView.backgroundColor = [UIColor clearColor];
    [self addSubview:tempView];
    UIView  *tempView2 = [[UIView alloc]init];
    tempView2.backgroundColor = [UIColor clearColor];
    [self addSubview:tempView2];
    [tempView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.navLabel.mas_bottom);
        make.left.equalTo(self.navLabel.mas_left);
        make.height.equalTo(@50);
        make.width.equalTo(self.mas_width).multipliedBy(0.55);
    }];
    
    UILabel *timeLabel = [[UILabel alloc]init];
    timeLabel.backgroundColor = [UIColor clearColor];
    timeLabel.text = @"时间:";
    [tempView addSubview:timeLabel];
    
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(tempView.centerY);
        make.left.equalTo(tempView.mas_left).offset(FiveOffsetViewMargin);
        make.height.equalTo(@40);
        make.width.equalTo(@40);
    }];
    
    UITextField *timeTextField = [[UITextField alloc]init];
    timeTextField.backgroundColor = [UIColor clearColor];
    timeTextField.layer.cornerRadius = kLayerCornerRadius;
    timeTextField.clipsToBounds = YES;
    timeTextField.layer.borderWidth = kLayerBorderWidth;
    timeTextField.layer.borderColor = kTextFieldBorderColor;
    [tempView addSubview:timeTextField];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"timeBtn"] forState:0];
    [tempView addSubview:button];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(tempView.height).multipliedBy(3/4.1f);
        make.width.equalTo(button.height).multipliedBy(9/10.0f);
        make.centerY.equalTo(tempView.centerY);
        make.right.equalTo(tempView.mas_right).offset(-FiveOffsetViewMargin);
    }];
    
    [timeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(button.centerY);
        make.height.equalTo(button.mas_height);
        make.left.equalTo(timeLabel.mas_right).offset(FiveOffsetViewMargin);
        make.right.equalTo(button.left).offset(-FiveOffsetViewMargin);
    }];
    
    [tempView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tempView);
        make.left.equalTo(tempView.mas_right);
        make.height.equalTo(@50);
        make.width.equalTo(self.mas_width).multipliedBy(0.45);
    }];
    
    UILabel *label2 = [[UILabel alloc]init];
    label2.backgroundColor = [UIColor clearColor];
    label2.text = @"登记人：";
    [tempView2  addSubview:label2];
    
    UITextField *textField2 = [[UITextField alloc]init];
    textField2.backgroundColor = [UIColor clearColor];
    textField2.layer.cornerRadius = kLayerCornerRadius;
    textField2.clipsToBounds = YES;
    textField2.layer.borderWidth = kLayerBorderWidth;
    textField2.layer.borderColor = kTextFieldBorderColor;
    [tempView2 addSubview:textField2];
    
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(tempView2.centerY);
        make.left.equalTo(tempView2.mas_left).offset(FiveOffsetViewMargin);
        make.height.equalTo(@40);
        make.width.equalTo(@70);
    }];
    
    [textField2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(tempView2.height).multipliedBy(3/4.0f);
        make.left.equalTo(label2.mas_right).offset(FiveOffsetViewMargin);
        make.centerY.equalTo(tempView2.centerY);
        make.right.equalTo(tempView2.mas_right).offset(-FiveOffsetViewMargin);
    }];
    
    UIView *recoredView = [[UIView alloc]init];
    recoredView.backgroundColor = [UIColor clearColor];
    [self addSubview:recoredView];
    
    UIView *questionView = [[UIView alloc]init];
    questionView.backgroundColor = [UIColor clearColor];
    [self addSubview:questionView];
    
    UIView *impressionView = [[UIView alloc]init];
    impressionView.backgroundColor = [UIColor clearColor];
    [self addSubview:impressionView];
    
    
    [recoredView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tempView2.mas_bottom).offset(TweentyOffsetViewMargin*2);
        make.left.equalTo(self.mas_left).offset(TenOffsetViewMargin);
        make.right.equalTo(self.mas_right).offset(-TenOffsetViewMargin);
        make.height.equalTo(@100);
    }];
    
    UIImageView  *titleImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"recored"]];
    titleImageView.contentMode = UIViewContentModeScaleAspectFit;
    [recoredView addSubview:titleImageView];
    
    UITextView  *textView = [[UITextView alloc]init];
    textView.backgroundColor = [UIColor clearColor];
    textView.layer.borderWidth = kLayerBorderWidth;
    textView.layer.borderColor = kTextView1BorderColor;
    textView.layer.cornerRadius = kLayerCornerRadius;
    textView.clipsToBounds = YES;
    [recoredView addSubview:textView];
    
    
    [titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(recoredView.mas_top);
        make.left.equalTo(recoredView.mas_left);
        make.width.equalTo(@120);
        make.height.equalTo(@25);
    }];
    
    [textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleImageView.mas_bottom);
        make.left.equalTo(titleImageView.mas_left);
        make.right.equalTo(recoredView.mas_right);
        make.bottom.equalTo(recoredView.mas_bottom);
    }];
    
    [questionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(recoredView.mas_bottom).offset(TweentyOffsetViewMargin*2);
        make.left.equalTo(self.mas_left).offset(TenOffsetViewMargin);
        make.right.equalTo(self.mas_right).offset(-TenOffsetViewMargin);
        make.height.equalTo(@100);
    }];
    UIImageView  *titleImageView1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"question"]];
    titleImageView1.contentMode = UIViewContentModeScaleAspectFit;
    [questionView addSubview:titleImageView1];
    
    UITextView  *textView1 = [[UITextView alloc]init];
    textView1.backgroundColor = [UIColor clearColor];
    textView1.layer.borderWidth = kLayerBorderWidth;
    textView1.layer.borderColor = kTextView2BorderColor;
    textView1.layer.cornerRadius = kLayerCornerRadius;
    textView1.clipsToBounds = YES;
    [questionView addSubview:textView1];

    [titleImageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(questionView.mas_top);
        make.left.equalTo(questionView.mas_left);
        make.width.equalTo(@120);
        make.height.equalTo(@25);
    }];
    
    [textView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleImageView1.mas_bottom);
        make.left.equalTo(titleImageView1.mas_left);
        make.right.equalTo(questionView.mas_right);
        make.bottom.equalTo(questionView.mas_bottom);
    }];
    
    
    [impressionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(questionView.mas_bottom).offset(TweentyOffsetViewMargin*2);
        make.left.equalTo(self.mas_left).offset(TenOffsetViewMargin);
        make.right.equalTo(self.mas_right).offset(-TenOffsetViewMargin);
        make.height.equalTo(@100);
    }];

    
    UIImageView  *titleImageView2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"impression"]];
    titleImageView2.contentMode = UIViewContentModeScaleAspectFit;
    [impressionView addSubview:titleImageView2];
    
    UITextView  *textView2 = [[UITextView alloc]init];
    textView2.backgroundColor = [UIColor clearColor];
    textView2.layer.borderWidth = kLayerBorderWidth;
    textView2.layer.borderColor = kTextView3BorderColor;
    textView2.layer.cornerRadius = kLayerCornerRadius;
    textView2.clipsToBounds = YES;
    [impressionView addSubview:textView2];


    [titleImageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(impressionView.mas_top);
        make.left.equalTo(impressionView.mas_left);
        make.width.equalTo(@120);
        make.height.equalTo(@25);
    }];
   
    [textView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleImageView2.mas_bottom);
        make.left.equalTo(titleImageView2.mas_left);
        make.right.equalTo(impressionView.mas_right);
        make.bottom.equalTo(impressionView.mas_bottom);
    }];
}

#pragma mark - event Reponse

- (void)cancleButtonEvent:(UIButton *)button {
    
    [self setHidden:YES];

}

#pragma mark - getter
- (UILabel *)navLabel {
    if (!_navLabel) {
        _navLabel = [[UILabel alloc]init];
        _navLabel.userInteractionEnabled = YES;
        _navLabel.backgroundColor = [UIColor colorWithRed:0.8941 green:0.9098 blue:0.9176 alpha:0.8];
        _navLabel.textAlignment = NSTextAlignmentCenter;
        _navLabel.text = @"张金国的到访纪录";
        [self addSubview:_navLabel];
    }
    return _navLabel;
}

- (UIButton *)cancleButton {
    if (!_cancleButton) {
        _cancleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancleButton.layer.masksToBounds = YES;
        _cancleButton.layer.cornerRadius = kLayerCornerRadius;
        _cancleButton.layer.borderWidth = kLayerBorderWidth*2;
        _cancleButton.backgroundColor = kButtonBackgroundColor;
        _cancleButton.layer.borderColor = kButtonBorderColor;
        [_cancleButton setTitle:@"取消" forState:0];
        [_cancleButton setTitleColor:kCancelBtnTitleColor forState:0];
        [_cancleButton addTarget:self action:@selector(cancleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_cancleButton];
    }
    return _cancleButton;
}
- (UIButton *)sureButton {
    if (!_sureButton) {
        _sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _sureButton.layer.masksToBounds = YES;
        _sureButton.layer.cornerRadius = kLayerCornerRadius;
        _sureButton.layer.borderWidth = kLayerBorderWidth*2;
        _cancleButton.backgroundColor = kButtonBackgroundColor;
        _sureButton.layer.borderColor = kButtonBorderColor;
        [_sureButton setTitle:@"保存" forState:0];
        [_sureButton setTitleColor:kSureBtnTitleColor forState:0];
        [self addSubview:_sureButton];
    }
    return _sureButton;
}

@end
